package words

import (
	"context"
	"github.com/gogf/gf/v2/util/gconv"
	"star/internal/logic/users"
	"star/internal/logic/words"
	"star/internal/model"

	"star/api/words/v1"
)

func (c *ControllerV1) RandList(ctx context.Context, req *v1.RandListReq) (res *v1.RandListRes, err error) {
	uid, err := users.GetUid(ctx)
	if err != nil {
		return nil, err
	}
	entityList, err := words.Rand(ctx, uid, req.Limit)
	if err != nil {
		return nil, err
	}
	var list []v1.List
	for _, ent := range entityList {
		list = append(list, v1.List{
			Id:               gconv.Uint(ent.Id),
			Word:             ent.Word,
			Definition:       ent.Definition,
			ProficiencyLevel: model.ProficiencyLevel(ent.ProficiencyLevel),
		})
	}
	return &v1.RandListRes{
		List: list,
	}, nil
}
